package com.kdl.webconfig.controller;


import com.kdl.webconfig.business.NewsBusiness;
import com.kdl.webconfig.vo.BaseRespVO;
import com.kdl.webconfig.vo.PageVO;
import com.kdl.webconfig.vo.config.NewsQueryReq;
import com.kdl.webconfig.vo.config.NewsVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 * 新闻配置表 前端控制器
 * </p>
 *
 * @author wcj
 * @since 2022-09-05
 */
@RestController
@RequestMapping("/webconfig/news")
@Api(value = "新闻管理接口", tags = {"新闻配置"})
public class NewsController {

    @Autowired
    NewsBusiness newsBusiness;

    @PostMapping("/page")
    @ApiOperation(value = "新闻列表")
    public BaseRespVO<PageVO<NewsVO>> page(@RequestBody@Valid NewsQueryReq newsQueryReq){
        PageVO<NewsVO> page = newsBusiness.page(newsQueryReq);
        return BaseRespVO.success(page);
    }

    @PostMapping("/saveOrUpdate")
    public BaseRespVO<Boolean> saveOrUpdate(@RequestBody @Valid NewsVO newsVO){
        Boolean aBoolean = newsBusiness.saveOrUpdate(newsVO);
        return BaseRespVO.success(aBoolean);
    }

    @PostMapping("/delete/{id}")
    @ApiOperation(value = "新闻保存")
    public BaseRespVO<Boolean> deleteById(@PathVariable Integer id){
        Boolean aBoolean = newsBusiness.deleteById(id);
        return BaseRespVO.success(aBoolean);
    }

}

